﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CreateMember : System.Web.UI.Page
{
    BookStoreDataContext bs = new BookStoreDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCreate_click(object sender, EventArgs e)
    {
        if (this.IsValid)
        {
            createMember();
        }

    }
    void createMember()
    {
        member mem = new member()
        {
            member_login = txtUser.Text.Trim(),
            member_password = txtPassword.Text.Trim(),
            phone = txtPhone.Text.Trim(),
            address = txtAddress.Text.Trim(),
            email = txtEmail.Text.Trim(),
            first_name = txtFirstName.Text.Trim(),
            last_name = txtLastName.Text.Trim()

        };
        bs.members.InsertOnSubmit(mem);
        bs.SubmitChanges();
        Session["fullName"] = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim();
        Response.Redirect("CreateMemberSuccess.aspx");
    }
    protected void cvLoginName_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool? isExist = false;
        if (bs.checkLoginExist(txtUser.Text.Trim(), ref isExist) >0)
        {
            args.IsValid = false;
            cvLoginName.ErrorMessage = "This login name is not availble";
        }
        else
        {
            cvLoginName.ErrorMessage = "";
            args.IsValid = true;
        }
    }
}